package com.xiyou.luckdraw.web.controller;

import com.xiyou.luckdraw.api.dto.user.ExchangeListRequest;
import com.xiyou.luckdraw.api.dto.user.ExchangeListResponse;
import com.xiyou.luckdraw.api.dto.user.UpdateExchangeRequest;
import com.xiyou.luckdraw.api.dto.user.UpdateExchangeResponse;
import com.xiyou.luckdraw.api.service.IUserExchangeService;
import com.xiyou.luckdraw.common.constants.ResultCodeConstants;
import com.xiyou.luckdraw.common.result.ResponseData;
import com.xiyou.luckdraw.common.result.ResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: UserExchangeController
 * @Description: 用户兑换记录
 * @author: limingxing
 * @Date: 2019-10-08 12:29
 */
@RestController
@RequestMapping("/exchange")
@Api(value="UserExchangeController",tags={"兑换记录接口"})
public class UserExchangeController {

    @Autowired
    private IUserExchangeService userExchangeService;

    @PostMapping("/list")
    @ApiOperation(value = "获取兑换记录列表")
    public ResponseData<ExchangeListResponse> list(@RequestBody ExchangeListRequest request) {
        ExchangeListResponse response = userExchangeService.getExchangeList(request);
        if (response.getCode().equals(ResultCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtils().setData(response);
        }
        return new ResponseUtils().setData(response.getMsg());

    }

    @PostMapping("/updateExchangeByStatus")
    @ApiOperation(value = "更新用户兑换状态")
    public ResponseData<UpdateExchangeResponse> updateExchangeByStatus(@RequestBody UpdateExchangeRequest request){
        UpdateExchangeResponse response = userExchangeService.updateExchangeByStatus(request);
        if (response.getCode().equals(ResultCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtils().setData(response);
        }
        return new ResponseUtils().setData(response.getMsg());
    }




}
